<?php

declare(strict_types=1);

namespace app\common\service\crm;

use app\common\traits\ServiceTrait;
use app\common\dao\crm\CustomerDao;

/**
 * 客户表 服务业务层(Service)
 * @author 吕玉冰
 * @date  2022-07-21
 * @copyright ©2022 泉州市盛筑信息科技有限公司 版权所有
 */
class OpenCustomerService
{
    protected $dao = null;

    public function __construct()
    {
        $this->dao = new CustomerDao();
    }

    use ServiceTrait;

    public function _list_where($data)
    {
        $where = [];
        $where[] = ["parent_id", "=", 0];
        $data['where'] = $where;
        return [
            'where' => isset($data['where']) ? $data['where'] : [],
            'order' => isset($data['order']) ? $data['order'] : [],
            'field' => isset($data['field']) ? $data['field'] : ['*'],
        ];
    }

    public function getAllCustomerInfo($page, $limit)
    {
        $list = $this->dao->getLists($page, $limit, [["parent_id", '<>', '0']]);
        $redata = [];
        foreach ($list['data'] as $key => $value) {
            $redata[$value['id']] = $this->dao->getRecordContractById($value['id']);
        }
        return $redata;
    }
}